﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;

/// <summary>
/// user 的摘要说明
/// </summary>
public class MemberUser: BaseClass
{
    string tableName = "MemberUser";
    public MemberUser()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }

    /// <summary>
    /// 分页查询
    /// </summary>
    /// <param name="pageSize">每页数</param>
    /// <param name="pageIndex">当前第多少页</param>
    /// <param name="count">数据总数</param>
    /// <param name="where">查询条件</param>
    /// <returns></returns>
    public ArrayList GetList(int pageSize, int pageIndex, out int count, string where)
    {
        //用户表
        string sqlcount = "select count(0) from " + tableName + " where 1 = 1 " + where;
        string sql = string.Format("select top {0} * from " + tableName + " where 1 = 1 {2} and ID not in(select top {1} id from " + tableName + " where 1 = 1 {2} order by id asc)order by id asc;"
              , pageSize, (pageIndex - 1) * pageSize, where);
        ArrayList data = new SQLHelper("getnum").Select(sql);
        count = Convert.ToInt32(new SQLHelper("getnum").ExecuteScalar(sqlcount));
        return data;
    }

    /// <summary>
    /// 新增一条
    /// </summary>
    /// <param name="n">参数</param>
    /// <param name="TableName">表名</param>
    /// <returns></returns>
    public int Insert(Hashtable n) {
        return BaseInsert(n, tableName);
    }

    /// <summary>
    /// 更新一条
    /// </summary>
    /// <param name="n"></param>
    /// <returns></returns>
    public int Update(Hashtable n)
    {
        return BaseUpdate(n, tableName);
    }
    public int UpdatePersonalCenter(Hashtable n)
    {
        string sql = "update MemberUser set loginPwd = @loginPwd,contact = @contact,remarks = @remarks where id = @id";
        int i = new SQLHelper("getnum").Execute(sql, n);
        return i;
    }
    /// <summary>
    /// 删除一条
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    public int Delete(string id)
    {
        return BaseDelete(id, tableName);
    }

    /// <summary>
    /// 任何条件查询一条
    /// </summary>
    /// <param name="n"></param>
    /// <returns></returns>
    public Hashtable GetModel(Hashtable n)
    {
        return BaseGetModel(n, tableName);
    }

    /// <summary>
    /// 指定参数查询
    /// </summary>
    /// <param name="p">参数</param>
    /// <param name="data">值</param>
    /// <returns></returns>
    public Hashtable GetModel(string p, string value)
    {
        string sql = "select * from " + tableName + " where " + p + " = '" + value + "'";
        ArrayList data = new SQLHelper("getnum").Select(sql);
        return data.Count > 0 ? (Hashtable)data[0] : null;
    }

    /// <summary>
    /// 获取所有会员用户下拉框
    /// </summary>
    /// <returns></returns>
    public DataTable GetUserList()
    {
        string sql = "select loginNum,id from " + tableName + " where  1 = 1 and userType <> '666'";
        DataTable dt = new SQLHelper("getnum").ExcuteQuery(sql);
        //DataRow Rows = dt.NewRow();
        //Rows["text"] = "全部";
        //dt.Rows.InsertAt(Rows, 0);
        return dt;
    }
}